 /* Replications do files for  `Estimating slim-majority effects in US state legislatures
with a regression discontinuity design under local
randomization assumptions' PSRM*/
 

/* There are two dta files. DataSlimMajPSRM.dta has the information at the state level.
   21480-0001-Data.dta has the district level electoral results.*/
 
 
 
  log using "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\Slim Majorities 2017\LogSlimMajPSRM.smcl", replace
 

******************** TABLE 1 *************************************************** 
 

use "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\Slim Majorities 2017\DataSlimMajPSRM.dta", replace 

 keep stabbr year tots toth dems demh reps reph demh_pct dems_pct reph_pct reps_pct LIV 
 
 sort  stabbr year

 save "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\Slim Majorities 2017\DataSlimMajPSRM_for_merge.dta", replace 

 
use "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\StateLegislatureElectionData\21480-0001-Data.dta", replace
 
 
* V5: state
* V6: year
* V8: District number
* V7: Senate or House seat
* V28: Margin of victory in that district
* V31: Election Outcome "1" means winner.
* Our unity of observation is the district in a state-year, so we only need one observation (one row) for the mother dataset.
* We keep the row of the winner in each district.

/* After the merge, this do file creates the variables nclose:
 the percentage of seats in that election in which the majority party won with  
a margin of victory below 5%
*/
 
keep  V5 V6 V8 V7 V14 V28   V11 V31

keep if V11=="G"

keep if V31==1 /*only winners*/
drop V11 V31

gen stabbr="CT" if  V5==1
replace stabbr="ME" if  V5==2
replace stabbr="MA" if  V5==3
replace stabbr="NH" if  V5==4
replace stabbr="RI" if  V5==5
replace stabbr="VT" if  V5==6
replace stabbr="DE" if  V5==11
replace stabbr="NJ" if  V5==12
replace stabbr="NY" if  V5==13
replace stabbr="PA" if  V5==14
replace stabbr="IL" if  V5==21
replace stabbr="IN" if  V5==22
replace stabbr="MI" if  V5==23
replace stabbr="OH" if  V5==24
replace stabbr="WI" if  V5==25
replace stabbr="IA" if  V5==31
replace stabbr="KS" if  V5==32
replace stabbr="MN" if  V5==33
replace stabbr="MO" if  V5==34
replace stabbr="NB" if  V5==35
replace stabbr="ND" if  V5==36
replace stabbr="SD" if  V5==37
replace stabbr="VA" if  V5==40
replace stabbr="AL" if  V5==41
replace stabbr="AR" if  V5==42
replace stabbr="FL" if  V5==43
replace stabbr="GA" if  V5==44
replace stabbr="LA" if  V5==45
replace stabbr="MS" if  V5==46
replace stabbr="NC" if  V5==47
replace stabbr="SC" if  V5==48
replace stabbr="TX" if  V5==49
replace stabbr="KY" if  V5==51
replace stabbr="MD" if  V5==52
replace stabbr="OK" if  V5==53
replace stabbr="TN" if  V5==54
replace stabbr="WV" if  V5==56
replace stabbr="AZ" if  V5==61
replace stabbr="CO" if  V5==62
replace stabbr="ID" if  V5==63
replace stabbr="MT" if  V5==64
replace stabbr="NV" if  V5==65
replace stabbr="NM" if  V5==66
replace stabbr="UT" if  V5==67
replace stabbr="WY" if  V5==68
replace stabbr="CA" if  V5==71
replace stabbr="OR" if  V5==72
replace stabbr="WA" if  V5==73
replace stabbr="AK" if  V5==81
replace stabbr="HW" if  V5==82


rename V6 year


sort  stabbr year




merge m:1 stabbr year  using  "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\Slim Majorities 2017\DataSlimMajPSRM_for_merge.dta"
* the data from the main file is necessary to identify the majority party and exclude states with unusual institutional framework

keep if _merge==3
drop _merge


* Only states with 2-chambers and similar relative powers
keep if LIV==1
* we drop the following states because they are not part of the working sample
drop if stabbr=="AK"
drop if stabbr=="HW"
drop if stabbr=="MN"
drop if stabbr=="NB"


******* Generate indicator variable for majority:
gen majority=1 if ((demh_pct>=0.5 & V14==100 & V7==9) | (demh_pct<=0.5 & V14==200 & V7==9)) | ((dems_pct>=0.5 & V14==100 & V7==8) | (dems_pct<=0.5 & V14==200 & V7==8))
replace majority=0 if majority==.
* if an election delivers 0.5 for both parties, any switch would work


****** Generating nclose

** nclose is the percentage of seats won by the majority that were close (less than 5% margin of victory)

bys stabbr year V7: egen n_close5=sum(V28<=5) if majority==1 & V28~=.
* a state-district election is defined as close is one of the majority party seats was won by less than a 5% margin of victory

* p_close is defined in terms of the fraction of seats
gen p_close5=n_close5/tots if V7==8
replace p_close5=n_close5/toth if V7==9


* The observation is a state year. We only need one row from each state-chamber year

bys stabbr year  V7: egen number_close5=mean(n_close5)
bys stabbr year  V7: egen percent_close5=mean(p_close5)

/* These are for visualiation of the partisan identity of the close state-district seats
bys stabbr year  V7: egen number_close5_dem=sum(demh_close5)
bys stabbr year  V7: egen number_close5_rep=sum(reph_close5)
*/

bys stabbr year  V7: gen n=_n
keep if n==1 


drop majority  n



**** Table 1 - results


*State House - number of seats

gen demh_num=demh-reph

count if    demh_num>=-1 & demh_num<=1  &  V7==9 & number_close5~=.
*  10
count if    demh_num>=-1 & demh_num<=1  &  V7==9 & number_close5>1 & number_close5~=.
*  10  100% i.e., in each slim majority of 1 there was at least 1 seat belonging to the majority part which had a margin of victory below 5%
count if    demh_num>=-2 & demh_num<=2  &  V7==9 & number_close5~=.
*  20
count if    demh_num>=-2 & demh_num<=2  &  V7==9 & number_close5>1 & number_close5~=.
*  19  95%%

* to visualize the partisan identiy of the close state-distric elections:
*br  year stabbr demh_num number_close5 number_close5_dem number_close5_rep   if    demh_num>=-1 & demh_num<=1  &  V7==9 & number_close5~=.
*br  year stabbr demh_num number_close5 number_close5_dem number_close5_rep demh reph  if    demh_num>=-2 & demh_num<=2  &  V7==9  & number_close5~=.


count if    demh_num>=-3 & demh_num<=3  &  V7==9 & number_close5~=.
*  34
count if    demh_num>=-3 & demh_num<=3  &  V7==9 & number_close5>1 & number_close5~=.
*  27  79%
count if    demh_num>=-1 & demh_num<=4  &  V7==9 & number_close5~=.
*  23
count if    demh_num>=-1 & demh_num<=4  &  V7==9 & number_close5>1 & number_close5~=.
*  18  78%
count if    demh_num>=-5 & demh_num<=5  &  V7==9 & number_close5~=.
*  60
count if    demh_num>=-5 & demh_num<=5  &  V7==9 & number_close5>1 & number_close5~=.
*  47  78%


*State House - percentage of seats

count if    demh_pct>=0.49 & demh_pct<=0.51  &  V7==9 & percent_close5~=.
*  18
count if    demh_pct>=0.49 & demh_pct<=0.51  &  V7==9 & percent_close5>0.01 & percent_close5~=.
*  15  83%
count if    demh_pct>=0.48 & demh_pct<=0.52  &  V7==9 & percent_close5~=.
*  40
count if    demh_pct>=0.48 & demh_pct<=0.52  &  V7==9 & percent_close5>0.02 & percent_close5~=.
*  25  62%
count if    demh_pct>=0.47 & demh_pct<=0.53  &  V7==9 & percent_close5~=.
*  61
count if    demh_pct>=0.47 & demh_pct<=0.53  &  V7==9 & percent_close5>0.03 & percent_close5~=.
*  33  54%
count if    demh_pct>=0.46 & demh_pct<=0.54  &  V7==9 & percent_close5~=.
*  84
count if    demh_pct>=0.46 & demh_pct<=0.54  &  V7==9 & percent_close5>0.04 & percent_close5~=.
*  41 49%
count if    demh_pct>=0.45 & demh_pct<=0.55  &  V7==9 & percent_close5~=.
*  96
count if    demh_pct>=0.45 & demh_pct<=0.55  &  V7==9 & percent_close5>0.05 & percent_close5~=.
*  41  43%





*State Senate - number of seats

gen dems_num=dems-reps

count if    dems_num>=-1 & dems_num<=1  &  V7==8 & number_close5~=.
*  41
count if    dems_num>=-1 & dems_num<=1  &  V7==8 & number_close5>1 & number_close5~=.
*  22  53%
count if    dems_num>=-2 & dems_num<=2  &  V7==8 & number_close5~=.
*  69
count if    dems_num>=-2 & dems_num<=2  &  V7==8 & number_close5>1 & number_close5~=.
*  32  46%
count if    dems_num>=-3 & dems_num<=3  &  V7==8 & number_close5~=.
*  98
count if    dems_num>=-3 & dems_num<=3  &  V7==8 & number_close5>1 & number_close5~=.
*  42  43%
count if    dems_num>=-1 & dems_num<=4  &  V7==8 & number_close5~=.
*  83
count if    dems_num>=-1 & dems_num<=4  &  V7==8 & number_close5>1 & number_close5~=.
*  37  45%
count if    dems_num>=-5 & dems_num<=5  &  V7==8 & number_close5~=.
*  164
count if    dems_num>=-5 & dems_num<=5  &  V7==8 & number_close5>1 & number_close5~=.
*  62  38%


*State Senate - percentage of seats

count if    dems_pct>=0.49 & dems_pct<=0.51  &  V7==8 & percent_close5~=.
*  18
count if    dems_pct>=0.49 & dems_pct<=0.51  &  V7==8 & percent_close5>0.01 & percent_close5~=.
*  15  83%
count if    dems_pct>=0.48 & dems_pct<=0.52  &  V7==8 & percent_close5~=.
*  43
count if    dems_pct>=0.48 & dems_pct<=0.52  &  V7==8 & percent_close5>0.02 & percent_close5~=.
*  36  84%
count if    dems_pct>=0.47 & dems_pct<=0.53  &  V7==8 & percent_close5~=.
*  67
count if    dems_pct>=0.47 & dems_pct<=0.53  &  V7==8 & percent_close5>0.03 & percent_close5~=.
*  38  57%
count if    dems_pct>=0.46 & dems_pct<=0.54  &  V7==8 & percent_close5~=.
*  83
count if    dems_pct>=0.46 & dems_pct<=0.54  &  V7==8 & percent_close5>0.04 & percent_close5~=.
*  31  37%
count if    dems_pct>=0.45 & dems_pct<=0.55  &  V7==8 & percent_close5~=.
*  115
count if    dems_pct>=0.45 & dems_pct<=0.55  &  V7==8 & percent_close5>0.05 & percent_close5~=.
*  36  31%




*************** Different data set for Table 2 onwards ***********************

use   "\\efim-gw.cse.bris.ac.uk\eclmdm\files\LIVPaper\Slim Majorities 2017\DataSlimMajPSRM.dta", replace 


 /*We only keep the years there was an legislative election
   The observation is a year with a legislative election.
   The running  variable is the election result that year.
   Outcomes are measured in the next year with a legislative election.
   This is so because the election takes place in the end of the year,
   typically November, and inauguration is typically in following January.
   */
 keep if election_les==1
 keep if LIV==1
  

 /* The data on seats won in an election in year t are coded under number of sets held in year t+1 
   (i.e., the are coded as the number of seats held by each party during the year an election is
    taking place). We perform the following change so that the number of seats in year t refer to the election held in year t*/
 
sort stabbr year
 by stabbr: gen demgov_new=demgov[_n+1]
 by stabbr: gen repgov_new=repgov[_n+1]
 by stabbr: gen tots_new=tots[_n+1]
 by stabbr: gen toth_new=toth[_n+1]
 by stabbr: gen dems_new=dems[_n+1]
 by stabbr: gen demh_new=demh[_n+1]
 by stabbr: gen reps_new=reps[_n+1]
 by stabbr: gen reph_new=reph[_n+1]
 by stabbr: gen demh_pct_new=demh_pct[_n+1]
 by stabbr: gen dems_pct_new=dems_pct[_n+1]
 by stabbr: gen reph_pct_new=reph_pct[_n+1]
 by stabbr: gen reps_pct_new=reps_pct[_n+1]
 by stabbr: gen midterm_new=midterm[_n+1]

drop demgov repgov tots toth dems demh reps reph demh_pct dems_pct reph_pct reps_pct  midterm

rename demgov_new demgov
rename repgov_new repgov
rename tots_new    tots
rename toth_new toth
rename dems_new dems
rename demh_new demh
rename reps_new reps
rename reph_new reph
rename demh_pct_new demh_pct
rename dems_pct_new dems_pct
rename reph_pct_new reph_pct
rename reps_pct_new reps_pct
rename midterm_new midterm
  



/* As described in the paper the sample compries states with the line-item veto.
   An observatino is a state-year with a legislative election. 
   The running variable is the election result that year.
   Outcomes are measure in the next year with a legislative election.
   This is so because the election takes place in the end of the year,
   typically November, and inauguration typically in following January.
   */
 

**House
gen majh_dem=1 if demh_pct>0.5 & demh_pct~=. 
replace majh_dem=0 if demh_pct<0.5 & demh_pct~=reph_pct
replace majh_dem=1 if demh_pct==0.5 & reph_pct<0.5  /* 2obs*/
* treatment can not be determined if there is a tie in the House


**Senate 
gen majs_dem=1 if dems_pct>0.5 & dems_pct~=.
replace majs_dem=0 if dems_pct<0.5 & dems_pct~=reps_pct
replace majs_dem=1 if dems_pct==0.5 & reps_pct<0.5  /* 3obs*/
replace majs_dem=1 if dems_pct==reps_pct  & demgov==1  /* 13 obs*/
replace majs_dem=0 if dems_pct==reps_pct & demgov==0  /* 9 obs*/
/* treatmetn can be defined in the Senate in case of a tie because of the Lieutenant Governmor.
 The states with ties are Arizona 1998 LT none, Delaware 1966 LT Dem(s), Florida 1992 LT Dem(s),
 Iowa 2004 LT Dem(s), Idaho 1990 LT Rep(***not same***), Indiana 1962 LT Rep(***not same****),
 Michigan 70/72 LT Rep(same), Montana 76 86 LT Dem(s), New Hampshire 74 76 78 LT none,
 New Jersey 1999 LT none, New Mexico 84 86 LT Dem/Rep(s), Nevada 64 LT Rep, Ohio 64 LT Rep(s),
 Oregon 2000 LT none, Pennsylvania 60 LT Dem(s), Virginia 95 LT Dem(**not same**), Wyoming 74 LT none
(s) means same as governor*/
replace majs_dem=0 if dems_pct==reps_pct & dems_pct~=. & stabbr=="ID"  /*  1 obs*/
replace majs_dem=0 if dems_pct==reps_pct & dems_pct~=. & stabbr=="IN"  /* 1 obs*/
replace majs_dem=1 if dems_pct==reps_pct & dems_pct~=. & stabbr=="VA"  /* 1 obs*/
replace majs_dem=. if dems_pct==reps_pct & dems_pct~=. & (stabbr=="AZ" | stabbr=="NH" | stabbr=="NJ" | stabbr=="OR" | stabbr=="WY")

	gen demh_num=demh-reph
    gen dems_num=dems-reps


 ** Previous Majority
 sort stabbr year 
 by stabbr: gen majh_dem_Lag= majh_dem[_n-1]
 by stabbr: gen demh_pct_Lag= demh_pct[_n-1]
 by stabbr: gen demh_num_Lag= demh_num[_n-1]
 by stabbr: gen demh_Lag= demh[_n-1]
 
 by stabbr: gen demgov_Lag2= demgov[_n-2]
 by stabbr: gen midterm_Lag= midterm[_n-1] /*midterm Lag makes it easier to interpret when splitting the sample*/

 *** INCUMBENCY-MAJORITY EFFECT **
 by stabbr: gen majh_dem_Next= majh_dem[_n+1]
 by stabbr: gen majh_dem_Next2= majh_dem[_n+2]
 by stabbr: gen majh_dem_Next3= majh_dem[_n+3]
 by stabbr: gen majh_dem_Next4= majh_dem[_n+4]
 by stabbr: gen majh_dem_Next5= majh_dem[_n+5]
 
 
 by stabbr: gen demh_pct_Next= demh_pct[_n+1]
 by stabbr: gen demh_num_Next= demh_num[_n+1]
 by stabbr: gen demh_Next= demh[_n+1]

 
 
 
 by stabbr: gen demgov_Next2= demgov[_n+2]

 
 ** Previous Majority
 by stabbr: gen majs_dem_Lag= majs_dem[_n-1]
 by stabbr: gen dems_pct_Lag= dems_pct[_n-1]
 by stabbr: gen dems_num_Lag= dems_num[_n-1]
 by stabbr: gen dems_Lag= dems[_n-1]

 *** INCUMBENCY-MAJORITY EFFECT **
 by stabbr: gen majs_dem_Next= majs_dem[_n+1]
 by stabbr: gen dems_pct_Next= dems_pct[_n+1]
 by stabbr: gen dems_num_Next= dems_num[_n+1]
 by stabbr: gen dems_Next= dems_num[_n+1]

 
 ** ECONOMIC EFFECTS
  by stabbr: gen sttottax_inc_Next= sttottax_inc[_n+1]
  by stabbr: gen sttottax_pc_Next= sttottax_pc[_n+1]
  by stabbr: gen stincpc_Next= stincpc[_n+1]
  by stabbr: gen unemp_Next= unemp[_n+1]

 

********************************************************
****************    TABLE 2   **************************
   
    gen stincpc_scaled=stincpc/1000


******************** 1% - 1% **********************************
******************** House - numbers ************************

** Add unequal as an option for the ttest to allow for unequal variances on either side of the cutoff.

** House - percentage
ttest majs_dem  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* 0.89
ttest majs_dem_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* 0.23 
ttest demgov  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.80
ttest demgov_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.52
ttest majh_dem_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.83
ttest stproptax_inc  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* 0.92
ttest sttottax_inc  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.92
ttest unemp  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.53
ttest stincpc_scaled  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.51
ttest midterm  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*0.28	

	
******************** 2 - 2 **********************************
******************** House - numbers ************************	

ttest majs_dem  if demh_num<=2 & demh_num>=-2  , by(majh_dem) unequal
* p-value: 0.27
ttest majs_dem_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) unequal
* p-value:1.00
ttest demgov  if demh_num<=2 & demh_num>=-2  , by(majh_dem) unequal
*0.41
ttest demgov_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) unequal
*0.55
ttest majh_dem_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) unequal
*0.67
ttest stproptax_inc  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* 0.91
ttest sttottax_inc  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*0.32 
ttest unemp  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*0.60
ttest midterm  if demh_num<=2 & demh_num>=-2  & election_les==1, by(majh_dem) unequal
* 0.41
ttest stincpc_scaled  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*0.40


** House - percentage
ttest majs_dem  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
* 0.52
ttest majs_dem_Lag  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
* 0.68
ttest demgov  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.90
ttest demgov_Lag  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.45
ttest majh_dem_Lag  if demh_pct<=0.52 & demh_pct>=0.48  , by(majh_dem) unequal
*0.92
ttest stproptax_inc  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.72
ttest sttottax_inc if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.15 ************************ 0.1494
ttest unemp  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.74
ttest midterm  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.82
ttest stincpc_scaled  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*0.40	
	


******************** 3 - 3 **********************************
******************** House - numbers ************************	

ttest majs_dem  if demh_num<=3 & demh_num>=-3  , by(majh_dem) unequal
* p-value: 0.22
ttest majs_dem_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) unequal
* p-value:0.89
ttest demgov  if demh_num<=3 & demh_num>=-3  , by(majh_dem) unequal
*0.73
ttest demgov_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) unequal
*0.77
ttest majh_dem_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) unequal
*0.28 
ttest stproptax_inc  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
* 0.82
ttest sttottax_inc  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
*0.20 
ttest unemp  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
*0.43
ttest midterm  if demh_num<=3 & demh_num>=-3  & election_les==1, by(majh_dem) unequal
* 0.98 
ttest stincpc_scaled  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
*0.56

** House - percentage
ttest majs_dem  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
* 0.16
ttest majs_dem_Lag  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
* 0.50
ttest demgov  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.53
ttest demgov_Lag  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.79
ttest majh_dem_Lag  if demh_pct<=0.53 & demh_pct>=0.47  , by(majh_dem) unequal
*0.28
ttest stproptax_inc  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.17 
ttest sttottax_inc if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.95
ttest unemp  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.56
ttest midterm  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.13  ********************
ttest stincpc_scaled  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*0.46	
	
	
	
******************** 4 - 4 **********************************
******************** House - numbers ************************	

ttest majs_dem  if demh_num<=4 & demh_num>=-4  , by(majh_dem) unequal
* p-value: 0.28
ttest majs_dem_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) unequal
* p-value:0.96
ttest demgov  if demh_num<=4 & demh_num>=-4  , by(majh_dem) unequal
*0.25
ttest demgov_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) unequal
*0.52
ttest majh_dem_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) unequal
*0.85
ttest stproptax_inc  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal
* 0.78
ttest sttottax_inc  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal
*0.40 
ttest unemp  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal
*0.33
ttest midterm  if demh_num<=4 & demh_num>=-4  & election_les==1, by(majh_dem) unequal
* 0.29
ttest stincpc_scaled  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal
*0.87

** House - percentage
ttest majs_dem  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
* 0.06 **********************
ttest majs_dem_Lag  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
* 0.14
ttest demgov  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.93
ttest demgov_Lag  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.30
ttest majh_dem_Lag  if demh_pct<=0.54 & demh_pct>=0.46  , by(majh_dem) unequal
*0.02  *******************
ttest stproptax_inc  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.03 *********
ttest sttottax_inc if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.71
ttest unemp  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.10 ****************
ttest midterm  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.37
ttest stincpc_scaled  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) unequal
*0.04 ****	
		
	

	
	
******************** 5 - 5 **********************************
******************** House - numbers ************************	

ttest majs_dem  if demh_num<=5 & demh_num>=-5  , by(majh_dem) unequal
* p-value: 0.13 *************
ttest majs_dem_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) unequal
* p-value:0.98
ttest demgov  if demh_num<=5 & demh_num>=-5  , by(majh_dem) unequal
*0.41
ttest demgov_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) unequal
*0.81
ttest majh_dem_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) unequal
*0.46
ttest stproptax_inc  if demh_num<=5 & demh_num>=-5 , by(majh_dem) unequal
* 0.67
ttest sttottax_inc  if demh_num<=5 & demh_num>=-5 , by(majh_dem) unequal
*0.97
ttest unemp  if demh_num<=5 & demh_num>=-5 , by(majh_dem) unequal
*0.43
ttest midterm  if demh_num<=5 & demh_num>=-5  & election_les==1, by(majh_dem) unequal
* 0.37
ttest stincpc_scaled  if demh_num<=5 & demh_num>=-5 , by(majh_dem) unequal
*0.43

** House - percentage
ttest majs_dem  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
* 0.01 **********************
ttest majs_dem_Lag  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
* 0.01 *******************
ttest demgov  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.89
ttest demgov_Lag  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.20
ttest majh_dem_Lag  if demh_pct<=0.55 & demh_pct>=0.45  , by(majh_dem) unequal
*0.00  *******************
ttest stproptax_inc  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.04 *********
ttest sttottax_inc if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.71
ttest unemp  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.01 ****************
ttest midterm  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.37
ttest stincpc_scaled  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) unequal
*0.04 ******************	
		
	
	

********** Senate *********


******************** 1 - 1 **********************************
******************** Senate - numbers ************************

ttest majh_dem  if dems_num<=1 & dems_num>=-1  , by(majs_dem) unequal
* p-value: 0.72
ttest majh_dem_Lag  if dems_num<=1 & dems_num>=-1  , by(majs_dem) unequal
*0.84
ttest demgov  if dems_num<=1 & dems_num>=-1  , by(majs_dem) unequal
*pvalue 0.07 ******************
ttest demgov_Lag2  if dems_num<=1 & dems_num>=-1  , by(majs_dem) unequal
*pvalue 0.83
ttest majs_dem_Lag  if dems_num<=1 & dems_num>=-1  , by(majs_dem) unequal
*0.12 ******************
ttest stproptax_inc  if dems_num<=1 & dems_num>=-1 , by(majs_dem) unequal
* 0.72
ttest sttottax_inc  if dems_num<=1 & dems_num>=-1 , by(majs_dem) unequal
*0.97
ttest unemp  if dems_num<=1 & dems_num>=-1 , by(majs_dem) unequal
*0.36
ttest midterm  if dems_num<=1 & dems_num>=-1  & election_les==1, by(majs_dem) unequal
* 0.71
ttest stincpc_scaled  if dems_num<=1 & dems_num>=-1 , by(majs_dem) unequal
*0.61



** Senate - percentage
ttest majh_dem  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) unequal
* p-value: 0.78
ttest majh_dem_Lag  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) unequal
*0.32
ttest demgov  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) unequal
*pvalue 0.16 
ttest demgov_Lag2  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) unequal
*pvalue 0.66
ttest majs_dem_Lag  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) unequal
*0.01 *******************
ttest stproptax_inc  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) unequal
* 0.84
ttest sttottax_inc  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) unequal
*0.37
ttest unemp  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) unequal
*0.52
ttest midterm  if dems_pct<=0.51  &  dems_pct>=0.49  & election_les==1, by(majs_dem) unequal
* 1.00
ttest stincpc_scaled  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) unequal
*0.42



******************** 2 - 2 **********************************
******************** Senate - numbers ************************

ttest majh_dem  if dems_num<=2 & dems_num>=-2  , by(majs_dem) unequal
* p-value: 0.44
ttest majh_dem_Lag  if dems_num<=2 & dems_num>=-2  , by(majs_dem) unequal
*0.85
ttest demgov  if dems_num<=2 & dems_num>=-2  , by(majs_dem) unequal
*pvalue 0.69 
ttest demgov_Lag2  if dems_num<=2 & dems_num>=-2  , by(majs_dem) unequal
*pvalue 0.88
ttest majs_dem_Lag  if dems_num<=2 & dems_num>=-2  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_num<=2 & dems_num>=-2 , by(majs_dem) unequal
* 0.57
ttest sttottax_inc  if dems_num<=2 & dems_num>=-2 , by(majs_dem) unequal
*0.76
ttest unemp  if dems_num<=2 & dems_num>=-2 , by(majs_dem) unequal
*0.54
ttest midterm  if dems_num<=2 & dems_num>=-2  & election_les==1, by(majs_dem) unequal
* 0.66
ttest stincpc_scaled  if dems_num<=2 & dems_num>=-2 , by(majs_dem) unequal
*0.72


** Senate - percentage
	
ttest majh_dem  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) unequal
* p-value: 0.44
ttest majh_dem_Lag  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) unequal
*0.89
ttest demgov  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) unequal
*pvalue 0.05 ******************
ttest demgov_Lag2  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) unequal
*pvalue 0.92
ttest majs_dem_Lag  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) unequal
*0.05 ******************
ttest stproptax_inc  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) unequal
* 0.29
ttest sttottax_inc  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) unequal
*0.67
ttest unemp  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) unequal
*0.44
ttest midterm  if dems_pct<=0.52  &  dems_pct>=0.48  & election_les==1, by(majs_dem) unequal
* 0.69
ttest stincpc_scaled  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) unequal
*0.17

******************** 3 - 3 **********************************
******************** Senate - numbers ************************

ttest majh_dem  if dems_num<=3 & dems_num>=-3  , by(majs_dem) unequal
* p-value: 0.04 ****************
ttest majh_dem_Lag  if dems_num<=3 & dems_num>=-3  , by(majs_dem) unequal
*0.17
ttest demgov  if dems_num<=3 & dems_num>=-3  , by(majs_dem) unequal
*pvalue 0.41 
ttest demgov_Lag2  if dems_num<=3 & dems_num>=-3  , by(majs_dem) unequal
*pvalue 0.37
ttest majs_dem_Lag  if dems_num<=3 & dems_num>=-3  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_num<=3 & dems_num>=-3 , by(majs_dem) unequal
* 0.63
ttest sttottax_inc  if dems_num<=3 & dems_num>=-3 , by(majs_dem) unequal
*0.76
ttest unemp  if dems_num<=3 & dems_num>=-3 , by(majs_dem) unequal
*0.47
ttest midterm  if dems_num<=3 & dems_num>=-3  & election_les==1, by(majs_dem) unequal
* 0.96
ttest stincpc_scaled  if dems_num<=3 & dems_num>=-3 , by(majs_dem) unequal
*0.98


** Senate - percentage

ttest majh_dem  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) unequal
* p-value: 0.21
ttest majh_dem_Lag  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) unequal
*0.33
ttest demgov  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) unequal
*pvalue 0.46
ttest demgov_Lag2  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) unequal
*pvalue 0.59
ttest majs_dem_Lag  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) unequal
* 0.53
ttest sttottax_inc  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) unequal
*0.72
ttest unemp  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) unequal
*0.44
ttest midterm  if dems_pct<=0.53  &  dems_pct>=0.47  & election_les==1, by(majs_dem) unequal
* 0.77
ttest stincpc_scaled  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) unequal
*0.48


******************** 4 - 4 **********************************
******************** Senate - numbers ************************

ttest majh_dem  if dems_num<=4 & dems_num>=-4  , by(majs_dem) unequal
* p-value: 0.02 ****************
ttest majh_dem_Lag  if dems_num<=4 & dems_num>=-4  , by(majs_dem) unequal
*0.02 *************************
ttest demgov  if dems_num<=4 & dems_num>=-4  , by(majs_dem) unequal
*pvalue 0.77
ttest demgov_Lag2  if dems_num<=4 & dems_num>=-4  , by(majs_dem) unequal
*pvalue 0.22
ttest majs_dem_Lag  if dems_num<=4 & dems_num>=-4  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_num<=4 & dems_num>=-4 , by(majs_dem) unequal
* 0.67
ttest sttottax_inc  if dems_num<=4 & dems_num>=-4 , by(majs_dem) unequal
*0.64
ttest unemp  if dems_num<=4 & dems_num>=-4 , by(majs_dem) unequal
*0.28
ttest midterm  if dems_num<=4 & dems_num>=-4  & election_les==1, by(majs_dem) unequal
* 0.74
ttest stincpc_scaled  if dems_num<=4 & dems_num>=-4 , by(majs_dem) unequal
*0.36


** Senate - percentage
	
ttest majh_dem  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) unequal
* p-value: 0.34
ttest majh_dem_Lag  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) unequal
*0.45
ttest demgov  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) unequal
*pvalue 0.69
ttest demgov_Lag2  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) unequal
*pvalue 0.40
ttest majs_dem_Lag  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) unequal
* 0.24
ttest sttottax_inc  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) unequal
*0.74
ttest unemp  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) unequal
*0.23
ttest midterm  if dems_pct<=0.54  &  dems_pct>=0.46  & election_les==1, by(majs_dem) unequal
* 0.96
ttest stincpc_scaled  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) unequal
*0.69


******************** 5 - 5 **********************************
******************** Senate - numbers ************************

ttest majh_dem  if dems_num<=5 & dems_num>=-5  , by(majs_dem) unequal
* p-value: 0.03 ****************
ttest majh_dem_Lag  if dems_num<=5 & dems_num>=-5  , by(majs_dem) unequal
*0.04 *************************
ttest demgov  if dems_num<=5 & dems_num>=-5  , by(majs_dem) unequal
*pvalue 0.82
ttest demgov_Lag2  if dems_num<=5 & dems_num>=-5  , by(majs_dem) unequal
*pvalue 0.35
ttest majs_dem_Lag  if dems_num<=5 & dems_num>=-5  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_num<=5 & dems_num>=-5 , by(majs_dem) unequal
* 0.37
ttest sttottax_inc  if dems_num<=5 & dems_num>=-5 , by(majs_dem) unequal
*0.22 
ttest unemp  if dems_num<=5 & dems_num>=-5 , by(majs_dem) unequal
*0.15
ttest midterm  if dems_num<=5 & dems_num>=-5  & election_les==1, by(majs_dem) unequal
* 0.82
ttest stincpc_scaled  if dems_num<=5 & dems_num>=-5 , by(majs_dem) unequal
*0.17


** Senate - percentage
	
ttest majh_dem  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) unequal
* p-value: 0.33
ttest majh_dem_Lag  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) unequal
*0.17
ttest demgov  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) unequal
*pvalue 0.83
ttest demgov_Lag2  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) unequal
*pvalue 0.58
ttest majs_dem_Lag  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) unequal
*0.00 ******************
ttest stproptax_inc  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) unequal
* 0.22
ttest sttottax_inc  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) unequal
*0.63 
ttest unemp  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) unequal
*0.49
ttest midterm  if dems_pct<=0.55  &  dems_pct>=0.45  & election_les==1, by(majs_dem) unequal
* 0.49
ttest stincpc_scaled  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) unequal
*0.90



**************************** Histogrgam - mass points *********************
***************************************************************************

 hist demh_num if demh_num>=-5 & demh_num<=5 & majh_dem~=., bin(200) freq

 hist demh_pct if demh_pct>=0.45 & demh_pct<=.55 & demh_pct~=0.5 , bin(200) freq



 hist dems_num if dems_num>=-5 & dems_num<=5 & majh_dem~=. , bin(200) freq

 hist dems_pct if dems_pct>=0.45 & dems_pct<=.55 & majs_dem~=. , bin(200) freq









**************************** TABLE 3 *************************************  
***************RDD CCT Method for continuous variables *******************
/*
CCT method
rdrobust sttottax_inc demh_pct , c(0.5)
*/

gen demh_num2=demh_num if majh_dem~=. & demh_num~=.
gen demh_pct2=demh_pct if majh_dem~=. & demh_pct~=.
gen dems_num2=dems_num if majs_dem~=. & dems_num~=. 
gen dems_pct2=dems_pct if majs_dem~=. & dems_pct~=.
/* redefinition necessary when maj when seats are 50% exact (mute for House - as ties are exclude)
   Many ties in Senate, but lieutenant governor breaks most  ties, so we reclassify
   ties to have 1 seat majority if the lieuteant has defined the majority.
   Note that this has no impact in the comparison of means, only for estimatinon of function and graphically*/ 
replace dems_num2=1 if dems_num==0 & majs_dem==1
replace dems_num2=-1 if dems_num==0 & majs_dem==0
replace dems_pct2=0.501 if dems_pct==0.5 & majs_dem==1
replace dems_pct2=0.499 if dems_pct==0.5 & majs_dem==0

replace demh_num2=1 if demh_num==0 & majh_dem==1
replace demh_num2=-1 if demh_num==0 & majh_dem==0
replace demh_pct2=0.501 if demh_pct==0.5 & majh_dem==1
replace demh_pct2=0.499 if demh_pct==0.5 & majh_dem==0




************************** House CCT *****

*** House balance numbers ***
rdrobust majs_dem demh_num2 , c(0)
*0.1 p 0.59 
rdrobust majs_dem_Lag demh_num2 , c(0)
*-0.04 p 0.57
rdrobust majh_dem_Lag demh_num2 , c(0)
*-0.07 p 0.38
rdrobust demgov demh_num2 , c(0)
*-0.05 p 0.80
rdrobust demgov_Lag demh_num2 , c(0)
*0.08 p 0.49
rdrobust midterm demh_num2 , c(0)
*0.11 p 0.31
rdrobust stincpc_scaled demh_num2 , c(0)
*0.43  p 0.98
rdrobust stproptax_inc demh_num2 , c(0)
*0.07 p 0.77
rdrobust sttottax_inc demh_num2 , c(0)
*-0.33 p 0.25
rdrobust unemp demh_num2 , c(0)
*0.10 p 82
rdrobust year demh_num2 , c(0)
* 2.7  p 0.73


*** House balance percentage ***
rdrobust majs_dem demh_pct2 , c(0.5)
* 0.06 p 0.93
rdrobust majs_dem_Lag demh_pct2 , c(0.5)
*-0.02 p 0.67
rdrobust majh_dem_Lag demh_pct2 , c(0.5)
* 0.01 p 0.75
rdrobust demgov demh_pct2 , c(0.5)
*-0.01 p 0.96
rdrobust demgov_Lag demh_pct2 , c(0.5)
*0.1 p 0.51
rdrobust midterm demh_pct2 , c(0.5)
*0.07 p 0.45 
rdrobust stincpc_scaled demh_pct2 , c(0.5)
*0.84 p 0.37
rdrobust stproptax_inc demh_pct2 , c(0.5)
*-0.33 p 0.26
rdrobust sttottax_inc demh_pct2 , c(0.5)
*-0.16 p 0.43
rdrobust unemp demh_pct2 , c(0.5)
*0.03 p 0.71
rdrobust year demh_pct2 , c(0.5)
*4.5  p 0.25


************************** Senate CCT *****

*** Senate balance numbers ***
rdrobust majs_dem_Lag dems_num2 , c(0) 
*0.20  p 0.39  assigning a maj of 1 if tie with a tie-breaker lieutenant 
rdrobust majh_dem dems_num2 , c(0)
* -0.0 p 0.60
rdrobust majh_dem_Lag dems_num2 , c(0)
* -0.01 p 0.89
rdrobust demgov dems_num2 , c(0) 
*0.07 p 0.37
rdrobust demgov_Lag dems_num2 , c(0)
* -0.06 p 0.90
rdrobust midterm dems_num2 , c(0)
*-0.02  p 0.84
rdrobust stincpc_scaled dems_num2 , c(0)
*0.65  p 0.51
rdrobust stproptax_inc dems_num2 , c(0)
*0.41 p 0.20
rdrobust sttottax_inc dems_num2 , c(0)
*-0.15 p 0.40
rdrobust unemp dems_num2 , c(0)
*0.21 p 0.64
rdrobust year dems_num2 , c(0)
* 0.6 p 0.31


*** Senate balance percentage ***

rdrobust majs_dem_Lag dems_pct2 , c(0.5)
*0.25 p 0.11
rdrobust majh_dem dems_pct2 , c(0.5)
* -0.02  0.90
rdrobust majh_dem_Lag dems_pct2 , c(0.5)
*0.016  p 0.75
rdrobust demgov dems_pct2 , c(0.5)
*0.20 p 0.11
rdrobust demgov_Lag dems_pct2 , c(0.5)
*-0.03 p 0.81
rdrobust midterm dems_pct2 , c(0.5)
*-0.00 p 0.80
rdrobust stincpc_scaled dems_pct2 , c(0.5)
*0.41  0.51
rdrobust stproptax_inc dems_pct2 , c(0.5)
*0.49 p 0.17
rdrobust sttottax_inc dems_pct2 , c(0.5)
*-0.04 p 0.86
rdrobust unemp dems_pct2 , c(0.5)
*0.24 p 0.60
rdrobust year dems_pct2 , c(0.5)
*1.78  p 0.77


 ********  McCrary Density tests  ***********
/*DCdensity demh_num2, breakpoint(0) gen(Xj Yj r0 fhat se_fhat)
drop Yj- se_fhat
 
 DCdensity demh_pct2, breakpoint(0.5) gen(Xj Yj r0 fhat se_fhat)
drop Yj- se_fhat

DCdensity dems_num2, breakpoint(0) gen(Xj Yj r0 fhat se_fhat)
drop Yj- se_fhat

 DCdensity dems_pct2, breakpoint(0.5) gen(Xj Yj r0 fhat se_fhat)
drop Yj- se_fhat
*/


************ TABLE 4 *****************************

**** 1 percentage/ 2 seats / CCT pct/ CCT Num  ****

ttest majh_dem_Next  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*Rep 0.61; Dem 0.5; diff -0.11 p:0.58
ttest majh_dem_Next  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*Rep 0.45; Dem 0.6; diff 0.14   p:0.53
rdrobust majh_dem_Next demh_pct2 , c(0.5)
* diff: -0.05 o: 0.7

ttest majs_dem_Next  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* Rep 0.46. Dem 0.5, diff 0.04 p 0.85
ttest majs_dem_Next  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*Rep 0.18; Dem 0.2; diff -0.02   p:0.92
rdrobust majs_dem_Next demh_pct2 , c(0.5)
* diff: 0.02 o: 0.8


ttest demgov_Next  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* Rep 0.31 Dem 0.25; diff -0.06 p: 0.76
ttest demgov_Next  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*Rep 0.18; Dem 0.4; diff 0.22   p:0.29
rdrobust demgov_Next demh_pct2 , c(0.5)
*0.08 p: 0.60


**************************************************************************************
******************** On-line Appendix ************************************************
**************************************************************************************




*************** TABLE A1 APPENDIX SMALL SAMPLE INFERENCE *************************

******************** 1% - 1% **********************************
******************** House - numbers ************************

rdrandinf majs_dem demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.0
rdrandinf majs_dem_Lag demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.35
rdrandinf demgov demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.0
rdrandinf demgov_Lag demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
*0.66
rdrandinf majh_dem_Lag demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.0
rdrandinf stproptax_inc demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.91
rdrandinf sttottax_inc demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.91
rdrandinf unemp demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.57
rdrandinf stincpc_scaled demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.51
rdrandinf midterm demh_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.40	
	
******************** 2 - 2 **********************************
******************** House - numbers ************************	

rdrandinf majs_dem demh_num2, cutoff(0) wl(-2) wr(2) 
* 0.42
rdrandinf majs_dem_Lag demh_num2, cutoff(0) wl(-2) wr(2) 
*1.0
rdrandinf demgov demh_num2, cutoff(0) wl(-2) wr(2) 
*0.43
rdrandinf demgov_Lag demh_num2, cutoff(0) wl(-2) wr(2) 
*0.67
rdrandinf majh_dem_Lag demh_num2, cutoff(0) wl(-2) wr(2) 
*1.0
rdrandinf stproptax_inc demh_num2, cutoff(0) wl(-2) wr(2) 
*0.92
rdrandinf sttottax_inc demh_num2, cutoff(0) wl(-2) wr(2) 
*0.32
rdrandinf unemp demh_num2, cutoff(0) wl(-2) wr(2) 
*0.61
rdrandinf midterm demh_num2, cutoff(0) wl(-2) wr(2) 
*0.46
rdrandinf stincpc_scaled demh_num2, cutoff(0) wl(-2) wr(2) 
*0.39



******************** 1 - 1 **********************************
******************** Senate - numbers ************************

rdrandinf majh_dem dems_num2, cutoff(0) wl(-1) wr(1) 
*0.77
rdrandinf majh_dem_Lag dems_num2, cutoff(0) wl(-1) wr(1) 
*1.0
rdrandinf demgov dems_num2, cutoff(0) wl(-1) wr(1) 
*0.11 ************
rdrandinf demgov_Lag2 dems_num2, cutoff(0) wl(-1) wr(1) 
* 1.0
rdrandinf majs_dem_Lag dems_num2, cutoff(0) wl(-1) wr(1) 
*0.14 ********
rdrandinf stproptax_inc dems_num2, cutoff(0) wl(-1) wr(1) 
* 0.70
rdrandinf sttottax_inc dems_num2, cutoff(0) wl(-1) wr(1) 
* 0.97
rdrandinf unemp dems_num2, cutoff(0) wl(-1) wr(1) 
* 0.35
rdrandinf midterm dems_num2, cutoff(0) wl(-1) wr(1) 
* 0.79
rdrandinf stincpc_scaled dems_num2, cutoff(0) wl(-1) wr(1) 
* 0.58


** Senate - percentage

rdrandinf majh_dem dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.0
rdrandinf majh_dem_Lag dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.59
rdrandinf demgov dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.13 *****
rdrandinf demgov_Lag2 dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.0
rdrandinf majs_dem_Lag dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.03 *****
rdrandinf stproptax_inc dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.84
rdrandinf sttottax_inc dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.39
rdrandinf unemp dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.50
rdrandinf midterm dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 1.00
rdrandinf stincpc_scaled dems_pct2, cutoff(0.5) wl(0.49) wr(0.51) 
* 0.41








*************** TABLE A2 APPENDIX Kolmogorov-Smirnov statistic for window selection *************************

****************** HOUSE  seat numners ***********
**** 2 seats *****
ksmirnov majs_dem  if demh_num<=2 & demh_num>=-2  , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) e
ksmirnov demgov  if demh_num<=2 & demh_num>=-2  , by(majh_dem) e
ksmirnov demgov_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_num<=2 & demh_num>=-2  , by(majh_dem) e
ksmirnov stproptax_inc  if demh_num<=2 & demh_num>=-2 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_num<=2 & demh_num>=-2 , by(majh_dem) e
*********************0.26 (group 1 Dem larger values)
ksmirnov unemp  if demh_num<=2 & demh_num>=-2 , by(majh_dem) e
ksmirnov midterm  if demh_num<=2 & demh_num>=-2  & election_les==1, by(majh_dem) e
ksmirnov stincpc_scaled  if demh_num<=2 & demh_num>=-2 , by(majh_dem) e

**** 3 seats *****
ksmirnov majs_dem  if demh_num<=3 & demh_num>=-3  , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) e
ksmirnov demgov  if demh_num<=3 & demh_num>=-3  , by(majh_dem) e
ksmirnov demgov_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_num<=3 & demh_num>=-3  , by(majh_dem) e
ksmirnov stproptax_inc  if demh_num<=3 & demh_num>=-3 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_num<=3 & demh_num>=-3 , by(majh_dem) e
*********************0.16 (group 1 Dem larger values)
ksmirnov unemp  if demh_num<=3 & demh_num>=-3 , by(majh_dem) e
ksmirnov midterm  if demh_num<=3 & demh_num>=-3  & election_les==1, by(majh_dem) e
ksmirnov stincpc_scaled  if demh_num<=3 & demh_num>=-3 , by(majh_dem) e

**** 4 seats *****
ksmirnov majs_dem  if demh_num<=4 & demh_num>=-4  , by(majh_dem) 
ksmirnov majs_dem_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) e
ksmirnov demgov  if demh_num<=4 & demh_num>=-4  , by(majh_dem) e
ksmirnov demgov_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_num<=4 & demh_num>=-4  , by(majh_dem) e
ksmirnov stproptax_inc  if demh_num<=4 & demh_num>=-4 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_num<=4 & demh_num>=-4 , by(majh_dem) e
*********************0. 13 (group 1 Dem larger values)
ksmirnov unemp  if demh_num<=4 & demh_num>=-4 , by(majh_dem) e
ksmirnov midterm  if demh_num<=4 & demh_num>=-4  & election_les==1, by(majh_dem) e
ksmirnov stincpc_scaled  if demh_num<=4 & demh_num>=-4 , by(majh_dem) e


**** 5 seats *****
ksmirnov majs_dem  if demh_num<=5 & demh_num>=-5  , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) e
ksmirnov demgov  if demh_num<=5 & demh_num>=-5  , by(majh_dem) e
ksmirnov demgov_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_num<=5 & demh_num>=-5  , by(majh_dem) e
ksmirnov stproptax_inc  if demh_num<=5 & demh_num>=-5 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_num<=5 & demh_num>=-5 , by(majh_dem) e
*********************0.43 (group 1 Dem larger values)
ksmirnov unemp  if demh_num<=5 & demh_num>=-5 , by(majh_dem) e
ksmirnov midterm  if demh_num<=5 & demh_num>=-5  & election_les==1, by(majh_dem) e
ksmirnov stincpc_scaled  if demh_num<=5 & demh_num>=-5 , by(majh_dem) e



****************** HOUSE  percentage seats**********

** House - 1 percent
ksmirnov majs_dem  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov demgov  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov demgov_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov stproptax_inc  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov unemp  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
ksmirnov stincpc_scaled  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e
*****************0.37 (group 1 Dem lower values)
ksmirnov midterm  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) e


** House - 2 percent
ksmirnov majs_dem  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov demgov  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov demgov_Lag  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov stproptax_inc  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov sttottax_inc  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
*****************0.05 (group 1 Dem higher values)
ksmirnov unemp  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov stincpc_scaled  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
ksmirnov midterm  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) e
		
		
** House - 3 percent
ksmirnov majs_dem  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov demgov  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov demgov_Lag  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov stproptax_inc  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
*****************0.09 (group 1 Dem higher values)
ksmirnov sttottax_inc  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov unemp  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov stincpc_scaled  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e
ksmirnov midterm  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) e

** House - 4 percent
ksmirnov majs_dem  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov demgov  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov demgov_Lag  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov stproptax_inc  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
*****************0.02 (group 1 Dem higher values)
ksmirnov sttottax_inc  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov unemp  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov stincpc_scaled  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
ksmirnov midterm  if demh_pct<=0.54 & demh_pct>=0.46 , by(majh_dem) e
		
** House - 5 percent
ksmirnov majs_dem  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov majs_dem_Lag  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov demgov  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov demgov_Lag  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov majh_dem_Lag  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov stproptax_inc  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
*****************0.01 (group 1 Dem higher values)
ksmirnov sttottax_inc  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov unemp  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov stincpc_scaled  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
ksmirnov midterm  if demh_pct<=0.55 & demh_pct>=0.45 , by(majh_dem) e
		

		
****************** SENATE seat numners ***********
		
** Senate - 1 seat		
ksmirnov majh_dem  if dems_num<=1 & dems_num>=-1  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_num<=1 & dems_num>=-1  , by(majs_dem) e
ksmirnov demgov  if dems_num<=1 & dems_num>=-1  , by(majs_dem) e
**************** 0.21  (Rep has higher vales than Dem)
ksmirnov demgov_Lag2  if dems_num<=1 & dems_num>=-1  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_num<=1 & dems_num>=-1  , by(majs_dem) e
ksmirnov stproptax_inc  if dems_num<=1 & dems_num>=-1 , by(majs_dem) e
**************** 0.21  (Rep has higher vales than Dem)
ksmirnov sttottax_inc  if dems_num<=1 & dems_num>=-1 , by(majs_dem) e
ksmirnov unemp  if dems_num<=1 & dems_num>=-1 , by(majs_dem) e
ksmirnov midterm  if dems_num<=1 & dems_num>=-1  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_num<=1 & dems_num>=-1 , by(majs_dem) e

** Senate - 2 seat		
ksmirnov majh_dem  if dems_num<=2 & dems_num>=-2  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_num<=2 & dems_num>=-2  , by(majs_dem) e
ksmirnov demgov  if dems_num<=2 & dems_num>=-2  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_num<=2 & dems_num>=-2  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_num<=2 & dems_num>=-2  , by(majs_dem) e
**************** 0.01  (Rep has lower vales than Rep)
ksmirnov stproptax_inc  if dems_num<=2 & dems_num>=-2 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_num<=2 & dems_num>=-2 , by(majs_dem) e
ksmirnov unemp  if dems_num<=2 & dems_num>=-2 , by(majs_dem) e
ksmirnov midterm  if dems_num<=2 & dems_num>=-2  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_num<=2 & dems_num>=-2 , by(majs_dem) e

** Senate - 3 seat		
ksmirnov majh_dem  if dems_num<=3 & dems_num>=-3  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_num<=3 & dems_num>=-3  , by(majs_dem) e
ksmirnov demgov  if dems_num<=3 & dems_num>=-3  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_num<=3 & dems_num>=-3  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_num<=3 & dems_num>=-3  , by(majs_dem) e
ksmirnov stproptax_inc  if dems_num<=3 & dems_num>=-3 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_num<=3 & dems_num>=-3 , by(majs_dem) e
**************** 0.13  (Rep has higher vales than Rep)
ksmirnov unemp  if dems_num<=3 & dems_num>=-3 , by(majs_dem) e
ksmirnov midterm  if dems_num<=3 & dems_num>=-3  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_num<=3 & dems_num>=-3 , by(majs_dem) e

** Senate - 4 seat		
ksmirnov majh_dem  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e
**************** 0.07  (Rep has lower values than Rep)
ksmirnov demgov  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e
ksmirnov stproptax_inc  if dems_num<=4 & dems_num>=-4, by(majs_dem) e
ksmirnov sttottax_inc  if dems_num<=4 & dems_num>=-4, by(majs_dem) e
ksmirnov unemp  if dems_num<=4 & dems_num>=-4, by(majs_dem) e
ksmirnov midterm  if dems_num<=4 & dems_num>=-4 & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_num<=4 & dems_num>=-4 , by(majs_dem) e

** Senate - 5 seat		
ksmirnov majh_dem  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e
ksmirnov demgov  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e
ksmirnov stproptax_inc  if dems_num<=5 & dems_num>=-5, by(majs_dem) e
**************** 0.01  (Rep has higher values than Rep)
ksmirnov sttottax_inc  if dems_num<=5 & dems_num>=-5, by(majs_dem) e
ksmirnov unemp  if dems_num<=5 & dems_num>=-5, by(majs_dem) e
ksmirnov midterm  if dems_num<=5 & dems_num>=-5 & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_num<=5 & dems_num>=-5 , by(majs_dem) e





** Senate - 1 percentage
ksmirnov majh_dem  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) e
ksmirnov demgov  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_pct<=0.51  &  dems_pct>=0.49  , by(majs_dem) e
**************** 0.05  (Rep has lower values than Rep)
ksmirnov stproptax_inc  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) e
ksmirnov unemp  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) e
ksmirnov midterm  if dems_pct<=0.51  &  dems_pct>=0.49  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_pct<=0.51  &  dems_pct>=0.49 , by(majs_dem) e


** Senate - 2 percentage
ksmirnov majh_dem  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) e
ksmirnov demgov  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_pct<=0.52  &  dems_pct>=0.48  , by(majs_dem) e
ksmirnov stproptax_inc  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) e
ksmirnov unemp  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) e
ksmirnov midterm  if dems_pct<=0.52  &  dems_pct>=0.48  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_pct<=0.52  &  dems_pct>=0.48 , by(majs_dem) e
**************** 0.05  (Rep has higher values than Dem)


** Senate - 3 percentage
ksmirnov majh_dem  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) e
ksmirnov demgov  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_pct<=0.53  &  dems_pct>=0.47  , by(majs_dem) e
**************** 0.01  (Rep has lower values than Dem)
ksmirnov stproptax_inc  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) e
ksmirnov unemp  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) e
ksmirnov midterm  if dems_pct<=0.53  &  dems_pct>=0.47  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_pct<=0.53  &  dems_pct>=0.47 , by(majs_dem) e


** Senate - 4 percentage
ksmirnov majh_dem  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) e
ksmirnov demgov  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_pct<=0.54  &  dems_pct>=0.46  , by(majs_dem) e
**************** 0.00  (Rep has lower values than Dem)
ksmirnov stproptax_inc  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) e
ksmirnov unemp  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) e
ksmirnov midterm  if dems_pct<=0.54  &  dems_pct>=0.46  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_pct<=0.54  &  dems_pct>=0.46 , by(majs_dem) e

** Senate - 5 percentage
ksmirnov majh_dem  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) e
ksmirnov majh_dem_Lag  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) e
ksmirnov demgov  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) e
ksmirnov demgov_Lag2  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) e
ksmirnov majs_dem_Lag  if dems_pct<=0.55  &  dems_pct>=0.45  , by(majs_dem) e
**************** 0.00  (Rep has lower values than Dem)
ksmirnov stproptax_inc  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) e
ksmirnov sttottax_inc  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) e
ksmirnov unemp  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) e
ksmirnov midterm  if dems_pct<=0.55  &  dems_pct>=0.45  & election_les==1, by(majs_dem) e
ksmirnov stincpc_scaled  if dems_pct<=0.55  &  dems_pct>=0.45 , by(majs_dem) e









*************** TABLE A3 APPENDIX larger windows *************************

ttest majh_dem_Next  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
*Rep 0.44; Dem 0.59; diff 0.15   p:0.36
ttest majh_dem_Next  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal
*Rep 0.42; Dem 0.56; diff 0.14   p:0.31


ttest majh_dem_Next  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
*Rep 0.58; Dem 0.5; diff -0.08   p:0.56
ttest majh_dem_Next  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal
*Rep 0.53; Dem 0.56; diff 0.03   p:0.77

ttest majs_dem_Next  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
ttest majs_dem_Next  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal

ttest majs_dem_Next  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
ttest majs_dem_Next  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal

ttest demgov_Next  if demh_num<=3 & demh_num>=-3 , by(majh_dem) unequal
ttest demgov_Next  if demh_num<=4 & demh_num>=-4 , by(majh_dem) unequal

ttest demgov_Next  if demh_pct<=0.52 & demh_pct>=0.48 , by(majh_dem) unequal
ttest demgov_Next  if demh_pct<=0.53 & demh_pct>=0.47 , by(majh_dem) unequal









*************** TABLE A4 APPENDIX Down-stream majority advantage *************************

** t+2 **
ttest majh_dem_Next2  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* -0.11  p0.58  12/13
ttest majh_dem_Next2  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*-0.03  p 0.90  11/10
rdrobust majh_dem_Next2 demh_pct2 , c(0.5)
* -0.15  p 0.24 103/105

** t+3 **
ttest majh_dem_Next3  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*-0.12  p 0.53 12/13
ttest majh_dem_Next3  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* 0.05  p 0.82 10/11
rdrobust majh_dem_Next3 demh_pct2 , c(0.5)
*-0.17  p 0.25 102/104

** t+4 **
ttest majh_dem_Next4  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* -0.13  p 0.49  12/13
ttest majh_dem_Next4  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* -0.04  p 0.84  10/11
rdrobust majh_dem_Next4 demh_pct2 , c(0.5)
* -0.14  p 0.40  113/140

** t+5 **
ttest majh_dem_Next5  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* -0.20  p 0.36  12/10
ttest majh_dem_Next5  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
* -0.08  p 0.74  8/11
rdrobust majh_dem_Next demh_pct2 , c(0.5)
* -0.05  p 0.50  143/166






****************** TABLE A5 APPENDIX Economic Outcomes**********************************



ttest unemp_Next  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
*Rep 5.3 Dem 5.4; diff 0.14 p: 0.78
ttest unemp_Next  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*Rep 5.7; Dem 5.6; diff -0.08  p:0.92
rdrobust unemp_Next demh_pct2 , c(0.5)
*-0.11 p: 0.54

ttest sttottax_inc_Next  if demh_num<=2 & demh_num>=-2 , by(majh_dem) unequal
* Rep 5.3 Dem 4.7; diff -0.60 p: 0.12
ttest sttottax_inc_Next  if demh_pct<=0.51 & demh_pct>=0.49 , by(majh_dem) unequal
*Rep 5.20; Dem 5.18; diff -0.02  p:0.97
rdrobust sttottax_inc_Next demh_pct2 , c(0.5)
*-0.2 p: 0.39




*********** TABLE  A6 - APPENDIX Governor Strength at the House  *************

gen majh_gov=1 if (majh_dem==1 & demgov==1) | (majh_dem==0 & repgov==1)
replace majh_gov=0 if majh_gov==.
sort stabbr year 
by stabbr: gen majh_gov_Next=majh_gov[_n+1]
by stabbr: gen majh_gov_Lag=majh_gov[_n-1]
by stabbr: gen majh_gov_Lag2=majh_gov[_n-2]


gen     gov_str_num=demh-reph if demgov==1
replace gov_str_num=reph-demh if repgov==1
*replace gov_str_num=. if gov_str_num==0
/* results for tax are robust including ties as above for majorties of 2.*/

*** Gov strength in the House  as continuous variable
gen gov_strengthh2=gov_strengthh if demh_pct2~=.
gen gov_str_num2=gov_str_num if demh_pct2~=.



*********** TABLE  A6 
ttest sttottax_inc_Next  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
* 0.59  p 0.07 ****
ttest sttottax_inc_Next  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
* 0.09 p 0.78 
rdrobust sttottax_inc_Next gov_strengthh2, c(0.5)
 *0.60 p 0.02 ***







***** control tests

ttest demgov  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.22  p 0.23
ttest majh_gov_Lag  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.52 p 0.54
ttest majh_dem  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.46 p 0.41
ttest majs_dem  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.51 p 0.62
ttest stproptax_inc   if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
* 0.98
ttest sttottax_inc   if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.23
ttest unemp   if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.90 
ttest midterm  if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.63
ttest stincpc_scaled if gov_str_num<=2 & gov_str_num>=-2 , by(majh_gov) unequal
*0.23	


ttest demgov  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.16 p 0.38 
ttest majh_gov_Lag  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
* 0.03 p 0.88
ttest majh_dem  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.22  p 0.24
ttest majs_dem  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.00  p 0.98

ttest stproptax_inc   if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
* 0.56
ttest sttottax_inc   if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.83
ttest unemp   if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.57
ttest midterm  if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.16
ttest stincpc_scaled if gov_strengthh<=0.51 & gov_strengthh>=0.49 , by(majh_gov) unequal
*0.85	
	

log close



